package com.google.mr.okhttptest.adapter;

import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.google.mr.okhttptest.R;
import com.google.mr.okhttptest.bean.ZhihuBean;
import com.jude.rollviewpager.adapter.StaticPagerAdapter;

import java.util.List;

/**
 * Created by Administrator on 2017/11/28.
 */

public class HeaderAdapter extends PagerAdapter {

    private final List<ZhihuBean.TopStoriesBean> mTopStoryList;

    public HeaderAdapter(List<ZhihuBean.TopStoriesBean> mTopStoris) {
        this.mTopStoryList=mTopStoris;
    }

    @Override
    public int getCount() {
        return mTopStoryList==null?0:mTopStoryList.size();
    }
    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view==object;
    }


    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(container.getContext()).inflate(R.layout.item_viewpager_imageview, container, false);
        ImageView imageview = view.findViewById(R.id.rollviewpager_item_iv);
        TextView textView= view.findViewById(R.id.rollviewpager_item_tv);
        textView.setText(mTopStoryList.get(position).getTitle());
        Glide.with(view.getContext()).load(mTopStoryList.get(position).getImage()).into(imageview);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
